import java.util.Random;
import java.util.Scanner;

public class App {
    public static void main(String[] args) throws Exception {
        //变量初始化
        Scanner sc = new Scanner(System.in);
        Random r = new Random();
        StringBuilder arr1 = new StringBuilder();
        int choose = 0;
        int haha = 0;

        //选择性循环
        first:while(true)
        {
            ban();//打印菜单
            System.out.printf("请输入命令：");
            choose = sc.nextInt();//记录输入的指令
            switch (choose) {
                case 1://添加元素
                {
                    arr1.append("CCTV");
                    check(arr1);
                    break;
                }
                case 2://反转元素
                {
                    arr1.reverse();
                    check(arr1);
                    break;
                }
                case 3://显示长度
                {
                    System.out.printf("\n%d\n\n",arr1.length());
                    break;
                }
                case 4://打印随机数量的"?"
                {
                    haha = r.nextInt(10) + 1;
                    System.out.printf("\n");
                    while(haha != 0)
                    {
                        System.out.printf("?");
                        haha--;
                    }
                    System.out.printf("\n\n");
                    break;
                }
                case 0://退出界面
                {
                    break first;
                }
                default://其他情况
                {
                    System.out.printf("\n所输入的命令不符合要求，请重新输入\n");
                    break;
                }
            }
    
        }
    }

    public static String check(StringBuilder arrs)
    {
        String str = new String();
        str = arrs.toString();
        System.out.printf("\nstr = " + str + "\n\n");

        return str;
    }

    public static void ban() {
        System.out.println("--------------------");
        System.out.println("    1.添加元素       ");
        System.out.println("    2.反转元素       ");
        System.out.println("    3.显示长度       ");
        System.out.println("    4.  ???         ");
        System.out.println("    0.退出界面       ");
        System.out.println("--------------------");

    }
}
